<%-- 
    Document   : AddItem
    Created on : Sep 19, 2011, 11:41:14 AM
    Author     : James
--%>

<%@page import="EntityState.ItemCategoryState"%>
<%@page import="EntityState.PartnerAccountState"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List, java.util.ArrayList"%>
<%@page import="java.util.ArrayList, BusinessLogic.Constants" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <title>FoodSage Partner Administration</title>


        <script language="javascript" type="text/javascript" src="../TransactWeb/js/jquery-1.6.4.min.js"></script>
        <script language="javascript" type="text/javascript" src="../TransactWeb/js/jquery.form.js"></script>
        <script type="text/javascript" src="../TransactWeb/js/fieldsetCollapse.js"></script>
        <script type="text/javascript" src="../TransactWeb/js/tcubmenu.js"></script>
        <script type="text/javascript" src="../TransactWeb/js/accordion.js"></script>
        <script type="text/javascript" src="../TransactWeb/js/scroller.js"></script>
        <script type="text/javascript" src="../TransactWeb/js/Utilities.js"></script>

        <link rel="stylesheet" type="text/css" href="../TransactWeb/css/gridsys.css" />
        <link rel="stylesheet" type="text/css" href="../TransactWeb/css/reset1.css" />
        <link rel="stylesheet" type="text/css" href="../TransactWeb/css/tcube.css" />
        <link href="../TransactWeb/css/gridsys.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" type="text/css" href="../TransactWeb/css/tcubaccd.css" />
        <script type="text/javascript">
            
            // Check Session to show relevant menus
            // Be sure to import Utilities.js in the script file	and declare partnerMenu as a servelet element
            window.onload = showPage('partnerMenu', 'leftnav');

            // If not logged in, use : 
            //window.onload = showPage('topMenu', 'topmenu');
            //IF logged in use : 
            window.onload = showPage('topMenulogout', 'topmenu');
           
            //welcome msg
            window.onload = showPage('welcomeMenu','welcome');

            //footer
            window.onload = showPage('partnerFooter','footer');
            
            $(document).ready(function() {
                $.ajax({
                    type: "GET",
                    cache: false,
                    url:  "GetInfo",
                    data: {
                        action: <%= Constants.GET_LIST_OF_PARTNER_CATEGORIES%>
                    },
                    success: function(response) { 
                        var categoryIDs = [];
                        var itemIDs     = [];
                        categoryIDs.push('<option value="0">Select a Category</option>');
                        itemIDs.push('<option>Select an Item</option>');
                        $(response).find("category").each(function() {
                            // Get category info
                            var id = $(this).find("catID").text();
                            var name = $(this).find("catName").text();
                            categoryIDs.push('<option value="', 
                            id, '">', 
                            name, '</option>');
                            itemIDs.push('<option disabled="true" style="font-weight:bold;"><b>', name, '</b></option>', '<option disabled="true"/>');
                            // Get items in the category
                            $(this).find("item").each(function() {
                                var id = $(this).find("itemID").text();
                                var name = $(this).find("itemName").text();
                                itemIDs.push('<option value="', id, '">', name, '</option>');
                            });
                            itemIDs.push('<option disabled="true"/>');
                        });
                        $("#categoryID").html(categoryIDs.join(''));
                        $("#subItem").html(itemIDs.join(''));
                    }, 
                    dataType: "xml"
                });
                
                $('#addItemForm').ajaxForm({ 
                    beforeSubmit: function() {
                        $("#addItemStatus").html("");
                    },
                    success: function(response){
                        var status = $(response).find("status").text();
                        $("#addItemStatus").html(status);
                    },
                    dataType: "xml"
                });
                
            }); 
        </script>
    </head>

    <body>
        <div class="container_12">
            <!-- Header Nav -->
            <div class="grid_3"><img src="../TransactWeb/img/reservation/foodsglogo.png" width="146" height="178" /></div>
            <div class="grid_9 nav">
                <div id="topmenu"></div>
            </div>
            <%
                PartnerAccountState pas = (PartnerAccountState) request.getAttribute("partner");
            %>
            <div class="grid_12">
                <hr size="3" color="#CC6600" />
            </div>
            <!-- Welcome Message -->
            <div class="grid_12 welcome">

                <div id="welcome"></div>
            </div>
            <!-- End Welcome Message-->

            <!-- End of Header Nav -->
            <!-- Menu / Planner -->
            <div class="grid_4">

                <div id="leftnav"></div>

            </div>
            <!--End Menu/ Planner -->
            <!-- Content -->
            <div class="grid_8 content">
                <!-- Content Header -->
                <table width="600" border="0">
                    <tr>
                        <td class="content_title">Item Management</td>
                    </tr>
                    <tr>
                        <td class="content_purpose">Create Item</td>
                    </tr>

                </table>
                <div id="addItemStatus" style="padding-left: 10px; color: #f7964f; margin-bottom: 10px;"></div>
                <form action="AddItemStatus" id="addItemForm" method="post" enctype="multipart/form-data">
                    <table width="500" border="0" class="formstyle">

                        <tr>
                            <td width="194">Item Name</td>
                            <td width="296"><input type="text" name="name" id="name" /></td>
                        </tr>
                        <tr>
                            <td width="194">Item Category</td>
                            <td><select name="categoryID" id="categoryID"></select></td>
                        </tr>
                        <tr>
                            <td width="194">Sub Items</td>
                            <td><select name="subItem" id="subItem" multiple="true" size="10"></select></td> 
                        </tr>
                        <%
                            for (int i = 1; i < Constants.FILE_MAX_NUM_OF_ITEM_PICTURE + 1; i++) {
                        %>
                        <tr>
                            <td width="194">Item Image <%= i%></td>
                            <td width="296"><input name="<%= i%>" type="file" /></td>
                        </tr>
                        <tr>
                            <td width="194">Item Description <%= i%></td>
                            <td width="296"><input type="text" name="<%= "description" + i%>" id="description" /></td>
                        </tr>
                        <%
                            }
                        %>
                        <tr>
                            <td>Description</td>
                            <td><input type="text" name="description" id="description" /></td>
                        </tr>
                        <tr>
                            <td>Discount</td>
                            <td><input type="text" name="discount" id="discount" /></td>
                        </tr>
                        <tr>
                            <td>Price</td>
                            <td><input type="text" name="price" id="price" /></td>
                        </tr>
                        <tr>
                            <td>Redeem Price</td>
                            <td><input type="text" name="redeemPrice" id="redeemPrice" /></td>
                        </tr>
                        <tr>
                            <td>For sale</td>
                            <td><input type="checkbox" name="selling" value="1" id="selling" /></td>
                        </tr>
                        <tr>
                            <td>Additional Loyalty Point</td>
                            <td><input type="text" name="additionalLoyaltyPoint" id="additionalLoyaltyPoint" /></td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td><input type="submit" id="submit2" value="Create Item" /></td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                    </table>
                </form>
                <!-- End Form -->
            </div>
            <!-- End Content -->
            <!-- Footer -->
            <div class="grid_12 footer">
                <div id="footer"></div>

            </div>
            <!-- End Footer-->
        </div>
    </body>
</html>
